package cn.stylefeng.guns.modular.system.warpper;

import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.modular.system.model.Mer;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.page.PageResult;
import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MerWrapper extends BaseControllerWrapper {
    public MerWrapper(Map<String, Object> single) {
        super(single);
    }

    public MerWrapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    public MerWrapper(Page<Map<String, Object>> page) {
        super(page);
    }

    public MerWrapper(PageResult<Map<String, Object>> pageResult) {
        super(pageResult);
    }


    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        String leavefactorydate = map.get("leavefactorydate").toString();
        if (ToolUtil.isNotEmpty(leavefactorydate)) {
            map.put("leavefactorydate",leavefactorydate.substring(0,10));
            map.put("categoryName", ConstantFactory.me().getCategoryName((Integer) map.get("category")));
            String pictureName = map.get("picture").toString();
            String reg = ".+(.JPEG|.jpeg|.JPG|.jpg|.png|.PNG)$";
            if(Pattern.matches(reg,pictureName)){
                map.put("pictureURL","<p><img src='/kaptcha/" +pictureName+ "' width='64px' height='64px'></p>");
            }else{
                map.put("pictureURL","未上传");
            }

        }

    }
}
